using System.Collections.Generic;
using FlowCanvas.Nodes;
using Yoozoo.Gameplay.Liberty.AI;

namespace Yoozoo.Gameplay.Liberty.StreetEvent
{
    public class PauseAllStreeFightMonsterAI : CallableActionNode<bool>
    {
        public override void Invoke(bool isPause)
        {
            Dictionary<int, StreetEventMonsterData> monsterId2InfoMap = StreetEventManager.GetInstance().monsterId2InfoMap;
            foreach (var m in monsterId2InfoMap.Values)
            {
                var aiEntity = LibertyAIUtils.AIManager.NpcBirthManager.GetNpc(m.uniqueId);
                if (aiEntity != null)
                {
                    if (isPause && aiEntity.graph.gameObject.activeSelf)
                    {
                        // 暂停行为树
                        aiEntity.graph.gameObject.SetActive(false);
                        // 停止AI移动
                        aiEntity.seeker.SetPriority(0.5f);
                        aiEntity.seeker.SetMaxSpeed(0);
                        aiEntity.data.maxSpeed = 0;
                        aiEntity.viewer.animator.SetFloat("Speed", 0);
                    }
                    else if (!isPause && !aiEntity.graph.gameObject.activeSelf)
                    {
                        // 开启行为树
                        aiEntity.graph.gameObject.SetActive(true);
                    }
                }
            }
        }
    }
}